PrintUnixDialog: Slightly ease page range entry
authorGuillaume Maudoux <layus.on@gmail.com>
Thu, 13 Jun 2019 21:11:56 +0000 (21:11 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 13 Jun 2019 21:11:56 +0000 (21:11 +0000)
Page ranges entry can now be focused directly, and will automatically
select the page ranges button when doing so.
This avoids the sometimes counter-intuitive previous behavior where the
entry was automatically focused when toggling the radio button, but the
user may still find themselves clicking uselessly in the text entry
because they scheduled it in their mental model.

gtk/gtkprintunixdialog.c
gtk/ui/gtkprintunixdialog.ui

index c1917999ebfee6771284adab454c9576c6f0f232..d2d516c56975915e01f382c3e4db07d96358edb7 100644 (file)
@@ -157,6 +157,9 @@ static void     emit_ok_response                   (GtkTreeView        *tree_vie
                                                    GtkTreePath        *path,
                                                    GtkTreeViewColumn  *column,
                                                    gpointer           *user_data);
+static gboolean page_range_entry_focus_changed     (GtkWidget          *entry,
+                                                    GParamSpec         *pspec,
+                                                    GtkPrintUnixDialog *dialog);
 static void     update_page_range_entry_sensitivity(GtkWidget          *button,
                                                    GtkPrintUnixDialog *dialog);
 static void     update_print_at_entry_sensitivity  (GtkWidget          *button,
@@ -562,6 +565,7 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   gtk_widget_class_bind_template_callback (widget_class, error_dialogs);
   gtk_widget_class_bind_template_callback (widget_class, emit_ok_response);
   gtk_widget_class_bind_template_callback (widget_class, selected_printer_changed);
+  gtk_widget_class_bind_template_callback (widget_class, page_range_entry_focus_changed);
   gtk_widget_class_bind_template_callback (widget_class, update_page_range_entry_sensitivity);
   gtk_widget_class_bind_template_callback (widget_class, update_print_at_entry_sensitivity);
   gtk_widget_class_bind_template_callback (widget_class, update_print_at_option);
@@ -2308,6 +2312,19 @@ draw_collate (GtkDrawingArea *da,
     }
 }
 
+static gboolean
+page_range_entry_focus_changed (GtkWidget          *entry,
+                                GParamSpec         *pspec,
+                                GtkPrintUnixDialog *dialog)
+{
+  GtkPrintUnixDialogPrivate *priv = gtk_print_unix_dialog_get_instance_private (dialog);
+
+  if (gtk_widget_has_focus (entry))
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
+
+  return FALSE;
+}
+
 static void
 update_page_range_entry_sensitivity (GtkWidget *button,
                                     GtkPrintUnixDialog *dialog)
@@ -2317,8 +2334,6 @@ update_page_range_entry_sensitivity (GtkWidget *button,
 
   active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
-  gtk_widget_set_sensitive (priv->page_range_entry, active);
-
   if (active)
     gtk_widget_grab_focus (priv->page_range_entry);
 }
index bacfd31e07f7b47d0f6c2edca60ebcce84c27e8f..ef905ecdbf7ce5902dcd81ef14b1553a105ce01a 100644 (file)
                                     </child>
                                     <child>
                                       <object class="GtkEntry" id="page_range_entry">
-                                        <property name="sensitive">0</property>
                                         <property name="can-focus">1</property>
                                         <property name="tooltip-text" translatable="yes">Specify one or more page ranges,
  e.g. 1–3, 7, 11</property>
                                         <property name="activates-default">1</property>
+                                        <signal name="notify::has-focus" handler="page_range_entry_focus_changed" swapped="no"/>
                                         <child internal-child="accessible">
                                           <object class="AtkObject" id="page_range_entry-atkobject">
                                             <property name="AtkObject::accessible-name" translatable="yes">Pages</property>